package com.example.base64;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * @author YAO
 * @create 2021-04-25 17:31
 */
public class base64Test {

    public static void main(String[] args) throws IOException {
        String content = "这是需要Base64编码的内容";
        //创建一个base64编码器
        BASE64Encoder base64Encoder = new BASE64Encoder();
        //执行base64编码操作
        String encodeString = base64Encoder.encode(content.getBytes(StandardCharsets.UTF_8));
        System.out.println(encodeString); //6L+Z5piv6ZyA6KaBQmFzZTY057yW56CB55qE5YaF5a65

        BASE64Decoder base64Decoder = new BASE64Decoder();
        byte[] bytes = base64Decoder.decodeBuffer(encodeString);
        String decodeString = new String(bytes,StandardCharsets.UTF_8);
        System.out.println(decodeString);
    }
}
